<?php

include_once('commonPdf.php');
include_once('inc/fce-evidence.inc.php');
include_once('inc/fce-slovniky.inc.php');

//nalezeni predmetu
$query = queryZobrazeniPredmetu($_GET["idPredmetu"]);
$row = $db->GetRow($query);

$reference = array();
$reference[0] = $row["idPredmetu"];
$reference[1] = $row["nazevPredmetu"];
aLog("evidence",$reference,8);

$pdf=new FPDF("P","mm","A4");
$pdf->Open();

//deklarace fontu
$pdf->AddFont('arial','','arial.php');
$pdf->AddFont('arial','B','arialbd.php');
$pdf->AddFont('arial','BI','arialbi.php');
$pdf->SetFont('arial');

//vytvoreni a zakladni nastaveni stranky
$pdf->AddPage();
$pdf -> SetTitle(textOut("Evidenční karta"));
$pdf->SetAuthor($config["app"]["jmeno"]);

// x-sirka, y-vyska
$pdf->SetFont('arial','B',16);
$pdf->Cell(0,15, textOut($row["nazevPredmetu"]),0,1,"C");

$pdf->SetFont('arial','B',10);
$pdf->SetXY(10,30);
$pdf->MultiCell(40,8, textOut("Evidenční číslo:")."\n".textOut("Inventární číslo:"),1);

$pdf->SetFont('arial','',10);
$pdf->SetXY(50,30);
$pdf->MultiCell(40,8, textOut($row["znaceniChronolog"])."\n".textOut($row["znaceniInventar"]),1);

//--Datace
$pdf->SetFont('arial','B',10);
$pdf->SetXY(90,30);
$pdf->MultiCell(0,8, textOut("Rok nálezu:")."\n".textOut("Datace vzniku:"),1);

$pdf->SetFont('arial','',10);
$pdf->SetXY(130,30);
$pdf->MultiCell(0,8, textOut($row["rokNalezu"])."\n".textOut($row["datace"]),1);

//--Lokace
$pdf->SetFont('arial','B',10);
$pdf->SetXY(10,46);
$pdf->MultiCell(0,8, textOut("Lokace aktuální:")."\n".textOut("Lokace stálá:"),1);

$pdf->SetFont('arial','',10);
$pdf->SetXY(50,46);
$pdf->MultiCell(0,8, textOut($row["nazevLokaceAktual"])."\n".textOut($row["nazevLokaceStala"]),1);

//--Způsob nabytí
$pdf->SetFont('arial','B',10);
$pdf->SetXY(90,46);
$pdf->MultiCell(40,8, textOut("Způsob nabytí:")."\n".textOut("Nabývací doklad:"),1);

$pdf->SetFont('arial','',10);
$pdf->SetXY(130,46);
$pdf->MultiCell(0,8, textOut($row["nazevZpusobuNabyti"])."\n".textOut($row["nabyvaciDoklad"]),0);

$pdf->SetFont('arial','B',10);
$pdf->SetXY(10,62);
$pdf->MultiCell(40,8, textOut("Druh:"),1);

$pdf->SetFont('arial','',10);
$pdf->SetXY(50,62);
$pdf->MultiCell(40,8, textOut($row["hesloNalezu"]),1);

//popis
$pdf->SetFont('arial','B',10);
$pdf->SetXY(10,70);
$pdf->Cell(40,15, textOut("Popis předmětu"));
$pdf->SetFont('arial','',10);
//$pdf->Cell(40,15, textOut($row["popisPredmetu"]));
$pdf->SetXY(10,80);
$pdf->Write(4,textOut($row["popisPredmetu"]));






//Slovniky
$pdf->Ln(10);
//$pdf->SetXY(10,95);
$pdf->SetFont('arial','B',10);
$pdf->Cell(40,5, textOut("Slovníky"));
$pdf->SetFont('arial','',10);
//$pdf->Cell(40,15, textOut($row["popisPredmetu"]));


//$pdf->Ln();

//$pdf->SetXY(10,95);

$querySl = "
                SELECT
                        nazevSlovniku,
                        idSlovniku
                FROM
                        core_slovniky
                WHERE
                        typSlovniku = 'USR'
                ORDER BY
                        nazevSlovniku ASC
                        ";
$resultSl = $db->Execute($querySl);
foreach($resultSl as $keySl => $rowSl) {
    $query = selectQuerySlovnik2Predmet($rowSl["idSlovniku"],$_GET["idPredmetu"]);
    $result = $db->Execute($query);
    $num = $result->RecordCount();
    
    if(!empty($num)) {
        
        
        //info slovniku
        $pdf->Ln();
        $pdf->SetFont('arial','U',10);
        $pdf->Cell(0,5, textOut($rowSl["nazevSlovniku"]),0);
        
        //polozky slovniku
        foreach($result as $key => $row) {
            $buffer .= $row["slovo"].', ';
        }
        $pdf->SetFont('arial','',10);
        $pdf->Write(5,textOut($buffer));
        unset($buffer);
        $pdf->Ln();
    }
}








//obrazek
$obrazek = 'data/predmety/'.$row["fotka"];

if(file_exists($obrazek) AND !empty($row["fotka"])) {
    list($OrigWidth, $OrigHeight) = getimagesize($obrazek);
    
    $noveVelikosti = pomeroveZmenseni($OrigWidth, $OrigHeight,50,50);
    $NewWidth = $noveVelikosti["width"];
    $NewHeight = $noveVelikosti["height"];
    
    $pdf->Ln();
    $pdf->SetFont('arial','B',10);
    $pdf->SetXY(10,190);
    $pdf->Cell(40,15, textOut("Obrázek"));
    $pdf->Image('data/predmety/'.$row["fotka"],10,200,$NewWidth,$NewHeight);
}


//oramovani
$pdf->Line(5,5,205,5); //horni
$pdf->Line(5,270,205,270); //dolni
$pdf->Line(5,5,5,270); //leve
$pdf->Line(205,5,205,270); //prave

//zapati
$pdf->SetFont('arial','',7);
$pdf->SetXY(5,275);
$pdf->Cell(0,0, textOut("Vytiskl: ".$_SESSION["usrSettings"]["jmenoUzivatele"]));
$pdf->SetXY(5,275);
$pdf->Cell(0,0, textOut("Vygeneroval ".$config["app"]["jmeno"]." v ".date("d. m. Y H:i:s")),0,0,"C");

$pdf->Output();


?>
